package com.example.springbootdemo.api.controller;

import com.example.springbootdemo.domin.VO.getAdminVO;
import com.example.springbootdemo.domin.entity.Admin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hello")
public class UserController {
    private final Logger logger = LoggerFactory.getLogger(UserController.class);
    private String mark;

    @GetMapping("/get")
    public int get(int id) {
        logger.debug("id为:{}", id);
        return id * 100;
    }

    @PostMapping("/getAdmin")
    public String getAdmin(@RequestBody Admin admin) {
        return admin.getName() + "," + admin.getSex() + "," + admin.getAge();
    }

    @PutMapping("/testAge")
    public getAdminVO getAdminVO(@RequestBody Admin admin) {
        if (Integer.parseInt(admin.getAge()) < 18) {
            mark = "未成年";
        }
        mark = "成年";
        getAdminVO adminVO = new getAdminVO();
        adminVO.setMark(mark);
        BeanUtils.copyProperties(admin, adminVO);
        return adminVO;
    }

    @DeleteMapping("/delete")
    public String delete(@RequestBody Admin admin) {
        return admin.getName() + "信息已经删除";
    }


}
